package com.ruoyi.flowable.listener.move.moveRepair;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.equ.domain.EquMove;
import com.ruoyi.equ.domain.EquRepair;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 移动-维修-5监听
 */
@Slf4j
@Component("moveRepairListener_5")
public class MoveRepairListener_5 implements ExecutionListener {
    private static final ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public void notify(DelegateExecution execution) {
        try {
            //科室验收结果
            String flag5_1 = execution.getVariable("flag5_1", String.class);
            String flag5_2 = execution.getVariable("flag5_2", String.class);
            String manyi = execution.getVariable("manyi", String.class);
            String reason5_1 = execution.getVariable("reason5_1", String.class);

            //移动-执行信息
            EquMove equMove = execution.getVariable("equMove", EquMove.class);
            Map<String, Object> executeInfoMap = objectMapper.readValue(equMove.getExecuteInfo(), new TypeReference<Map<String, Object>>() {});
            HashMap<String, Object> dataMap = new HashMap<>();
            dataMap.put("故障", flag5_1);
            dataMap.put("设备运行", flag5_2);
            dataMap.put("维修服务满意度", manyi);
            dataMap.put("原因", reason5_1);
            executeInfoMap.put("维修-科室验收结果", dataMap);
            String executeInfo = objectMapper.writeValueAsString(executeInfoMap);

            equMove.setExecuteInfo(executeInfo);
            execution.setVariable("equMove", equMove);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
